package com.douqu.game.core.config;

import com.douqu.game.core.config.common.CommonData;
import com.douqu.game.core.entity.GameObject;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.factory.LoadFactory;
import com.douqu.game.core.util.LoadUtils;
import com.douqu.game.core.util.LogUtils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author wangzhenfei
 *         2017-12-04 11:46
 *         vip特权配置
 */
public class VipConfig extends GameObject {

    public String previlege;
    /**Vip经验**/
    public int needRecharge;

    /**祭祀免费次数**/
    public CommonData[] altarFreeTimes;
    public Map<Integer, Integer>  altarFreeTimesMap = new HashMap<>();

    /**祭祀收费次数**/
    public CommonData[] altarPurchaseMax;
    public Map<Integer, Integer>  altarPurchaseMaxMap = new HashMap<>();

    /**购买竞技次数**/
    public int buyArenaMax;
    /**卡组额外卡牌数量**/
    public int additionalCard;
    /**Vip礼包ID**/
    public int gift;
    /**显示原价**/
    public int originalPrice;
    /**实际价格**/
    public int discountPrice;

    /**远征免费重置次数**/
    public int expeditionFreeTimes;

    /**远征购买次数**/
    public int expeditionPurchaseMax;

    /**竞技场免费次数*/
    public int arenaFreeTimes;

    /**采集每日次数*/
    public int dailyCollectTimes;

    /**BOSS战挑战次数*/
    public int bossChallengeTimes;

    /**可购买BOSS战挑战次数*/
    public int buyBossMax;

    /**争霸赛积分倍率*/
    public int hegemonyMul;

    /** 是否可聊天 */
    public boolean chat;

    @Override
    public boolean check()
    {
        if(altarFreeTimes == null)
        {
            LogUtils.error("VipConfig check altarFreeTimes is null -> id:" + id + " name:" + name);
            return false;
        }

        if(altarPurchaseMax == null)
        {
            LogUtils.error("VipConfig check altarPurchaseMax is null -> id:" + id + " name:" + name);
            return false;
        }

        if(DataFactory.getInstance(LoadFactory.isTestLoad()).getGameObject(DataFactory.DROP_GROUP_KEY, gift) == null){
            LogUtils.error("VipConfig check gift drop group is null -> gift:" + gift + " name:" + name);
            return false;
        }

        return true;
    }


    @Override
    public boolean setVariable(String key, String value)
    {
        if("altarFreeTimes".equals(key))
        {
            altarFreeTimes = LoadUtils.loadCommonDataToArray(key, value);
            if(LoadUtils.checkCommonData(altarFreeTimes, this.getClass(), key, DataFactory.ALTAR_KEY, id, true))
            {
                for(CommonData data : altarFreeTimes)
                {
                    altarFreeTimesMap.put(data.id, data.value);
                }
                return true;
            }
            else
                return false;
        }
        else  if("altarPurchaseMax".equals(key))
        {
            altarPurchaseMax = LoadUtils.loadCommonDataToArray(key, value);
            if(LoadUtils.checkCommonData(altarPurchaseMax, this.getClass(), key, DataFactory.ALTAR_KEY, id))
            {
                for(CommonData data : altarPurchaseMax)
                {
                    altarPurchaseMaxMap.put(data.id, data.value);
                }
                return true;
            }
            else
                return false;
        }
        else if("chat".equals(key))
        {
            chat = "1".equals(value);
            return true;
        }
        else
            return super.setVariable(key, value);
    }

    @Override
    public String toString() {
        return "VipConfig{" +
                "previlege='" + previlege + '\'' +
                ", needRecharge=" + needRecharge +
                ", altarFreeTimes=" + Arrays.toString(altarFreeTimes) +
                ", altarFreeTimesMap=" + altarFreeTimesMap +
                ", altarPurchaseMax=" + Arrays.toString(altarPurchaseMax) +
                ", altarPurchaseMaxMap=" + altarPurchaseMaxMap +
                ", buyArenaMax=" + buyArenaMax +
                ", additionalCard=" + additionalCard +
                ", gift=" + gift +
                ", originalPrice=" + originalPrice +
                ", discountPrice=" + discountPrice +
                ", expeditionFreeTimes=" + expeditionFreeTimes +
                ", expeditionPurchaseMax=" + expeditionPurchaseMax +
                ", arenaFreeTimes=" + arenaFreeTimes +
                ", dailyCollectTimes=" + dailyCollectTimes +
                ", bossChallengeTimes=" + bossChallengeTimes +
                ", buyBossMax=" + buyBossMax +
                ", hegemonyMul=" + hegemonyMul +
                '}';
    }
}
